import {baseUrl} from "./config.js"

// 首页接口
export function topList(){
	
	let listIds = ['3', '0', '2', '1']
	
	return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/toplist/detail`,
			method:'GET',
			data: {},
			success: res => {
				// console.log(res);
				let result = res.data.list;
				result.length = 4;			// 拿到前四项
				for(var i=0; i<listIds.length; i++){
					result[i].listId = listIds[i]
				}
				reslove(result)
			},
			fail: () => {},
			complete: () => {}
		})
	})
}

// 音乐列表接口
export function list(listId){
	console.log(listId, '-----------');
	return uni.request({
		url: `${baseUrl}/top/list?idx=${listId}`,
		method:'GET'
	})
}

// 音乐详情接口
// http://localhost:3000/song/detail?ids=483937795
export function songDetail(songId){
	return uni.request({
		url: `${baseUrl}/song/detail?ids=${songId}`,
		method: "GET"
	})
}
// 推荐歌曲列表接口
// http://localhost:3000/simi/song?id=483937795
export function songSimi(songId){
	return uni.request({
		url: `${baseUrl}/simi/song?id=${songId}`,
		method: "GET"
	})
}
// 评论接口
// http://localhost:3000/comment/music?id=483937795
export function songComment(songId){
	return uni.request({
		url: `${baseUrl}/comment/music?id=${songId}`,
		method: "GET"
	})
}
// 歌词接口
// http://localhost:3000/lyric?id=483937795
export function songLyric(songId){
	return uni.request({
		url: `${baseUrl}/lyric?id=${songId}`,
		method: "GET"
	})
}
// 音乐播放地址
// http://localhost:3000/song/url?id=483937795
export function songUrl(songId){
	return uni.request({
		url: `${baseUrl}/song/url?id=${songId}`,
		method: "GET"
	})
}

// 搜索接口
// http://localhost:3000/search/hot/detail     热搜榜
export function searchHot(){
	return uni.request({
		url: `${baseUrl}/search/hot/detail`,
		method: "GET"
	})
}
// http://localhost:3000/search?keywords=少年     搜索结果接口
export function searchWord(word){
	return uni.request({
		url: `${baseUrl}/search?keywords=${word}`,
		method: "GET"
	})
}
// http://localhost:3000/search/suggest?keyword=少年&type=mobile    搜索提示接口
export function searchSuggest(word){
	return uni.request({
		url: `${baseUrl}/search/suggest?keywords=${word}&type=mobile`,
		method: "GET"
	})
}